
#ifndef XDNS_DATA_H
#define XDNS_DATA_H

#include "xdns.h"

class XdnsData
{
public:
    XdnsData();
    virtual ~XdnsData();

    static XdnsError Init(XdnsData** data);
    static void Release(XdnsData* data);

    /*! Append data.

        @param buffer Buffer to append. This function does not take
                      ownership of this buffer.
        @param bufferSize Number of bytes to append.
        @return XE_Ok if success.
    */
    virtual XdnsError AppendData(unsigned char* buffer,
                                 size_t bufferSize
                                 ) = 0;

    /*! Set data from a position.
        
        @param position Start position to set data.
        @param buffer Buffer to set. This function does not take
                      ownership of this buffer.
        @param bufferSize Number of bytes to set.
        @return XE_Ok if success,
                XE_Range if the current data size is less than the
                size to set (position + bufferSize).
    */
    virtual XdnsError SetData(size_t position,
                              unsigned char* buffer,
                              size_t bufferSize
                              ) = 0;

    /*! Retrieve size of data from a position.

        @param buffer Buffer to retrieve data into. The size of this
                      buffer must be not less than the value of
                      parameter requestedSize.
        @param position Start position to retrieve data.
        @param requestedSize Requested size of data.
        @return Number of bytes retrieved.
    */
    virtual size_t GetData(unsigned char* buffer,
                           size_t position,
                           size_t requestedSize
                           ) const = 0;

    /*! Retrieve the total data size.

        @return Total data size.
    */
    virtual size_t GetDataSize() const = 0;

    /*! Clear all data.

        @return None.
    */
    virtual void Clear() = 0;

    /*! Clone this XdnsData object.

        @return The cloned XdnsData object if success, otherwise the NULL
                pointer is returned for the error of no enough memory.
    */
    virtual XdnsData* Clone() const = 0;

private:
    // Copy constructor and assignment operator are not supported.
    XdnsData(const XdnsData& anotherData);
    XdnsData& operator=(const XdnsData& anotherData);
};

#endif  // XDNS_DATA_H

